package cn.demo.reverseProxy.filter;


import cn.demo.reverseProxy.entity.UserContext;

/**
 * @Author: ljh
 * @Date: 2019/10/10 22:04
 * 将得到得头信息，储存到threadlocal变量里，
 * 该变量可以在用户请求得线程调用得任何方法中调用
 */
public class UserContextHolder {
    private static final ThreadLocal<UserContext> userContext =
            new ThreadLocal<UserContext>();

    public static final UserContext getContext() {
        UserContext context = userContext.get();

        if (context == null){
            context=creatContext();
            userContext.set(context);
        }
        return context;
    }
    public static final UserContext creatContext(){
        return new UserContext();
    }
}
